﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 蓝牙注册工具.BLL
{
    public class ConfigBLL
    {
     
        public static Model.ConfigModel GetConfigModel()
        {
            try
            {
                string iniPath = Environment.CurrentDirectory + "\\设置.ini";
                Model.ConfigModel configModel = new Model.ConfigModel()
                {
                    BtPortname = BtLabelTool.IniHelper.IniReadValue("信号", "蓝牙串口", iniPath),

                    ScanDelay = BtLabelTool.IniHelper.IniReadValue("信号", "蓝牙搜索时长", iniPath),

                    dBm = BtLabelTool.IniHelper.IniReadValue("信号", "蓝牙强度阈值", iniPath),

                    Channel1Portname = BtLabelTool.IniHelper.IniReadValue("串口", "通道1", iniPath),

                    Channel2Portname = BtLabelTool.IniHelper.IniReadValue("串口", "通道2", iniPath),

                    Channel3Portname = BtLabelTool.IniHelper.IniReadValue("串口", "通道3", iniPath),

                    Channel4Portname = BtLabelTool.IniHelper.IniReadValue("串口", "通道4", iniPath),

                    SignupUrl = BtLabelTool.IniHelper.IniReadValue("设备注册", "URL", iniPath),

                    SignupType = BtLabelTool.IniHelper.IniReadValue("设备注册", "TYPE", iniPath)
                };
                return configModel;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 保存配置文件
        /// </summary>
        public static void SaveConfigModel()
        {
            try
            {
                string iniPath = Environment.CurrentDirectory + "\\设置.ini";
                BtLabelTool.IniHelper.IniWriteValue("串口", "通道1", MainWindow.config.Channel1Portname, iniPath);

                BtLabelTool.IniHelper.IniWriteValue("串口", "通道2", MainWindow.config.Channel2Portname, iniPath);

                BtLabelTool.IniHelper.IniWriteValue("串口", "通道3", MainWindow.config.Channel3Portname, iniPath);

                BtLabelTool.IniHelper.IniWriteValue("串口", "通道4", MainWindow.config.Channel4Portname, iniPath);

                BtLabelTool.IniHelper.IniWriteValue("信号", "蓝牙串口", MainWindow.config.BtPortname, iniPath);
                BtLabelTool.IniHelper.IniWriteValue("信号", "蓝牙搜索时长", MainWindow.config.ScanDelay, iniPath);
                BtLabelTool.IniHelper.IniWriteValue("信号", "蓝牙强度阈值", MainWindow.config.dBm, iniPath);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
